// pages/comments/comments.js
const app = getApp()
const api = require("../../api/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    amount: '',
    value: 1,
    checked: true,
    type: 1, //0匿名评论 1实名评论,
    goodsId: '',
    avatarUrl:'',
    nickName:''
  },
  //select为选择是否匿名评论的功能项
  select(event) {
    this.setData({
      checked: event.detail,
    });
    if (this.data.checked) {
      this.setData({
        type: 1
      })
    } else {
      this.setData({
        type: 0
      })
    }
  },

  comment() {
    console.log(1)
    wx.request({
      url: api.commentGoods.url,
      method: api.commentGoods.method,
      data: {
        goodsId: this.data.goodsId,
        commenterId: app.globalData.id,
        content: this.data.amount,
        type: this.data.type
      },
      success:res=> {
        wx.showToast({
          title: '评价成功',
          icon: 'success'
        })
        wx.navigateBack({
          delta: 1,
        })
       
      }
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      goodsId: options.goods_id,
      avatarUrl:app.globalData.userInfo.avatarUrl,
      nickName:app.globalData.userInfo.nickName
    })
    console.log(app.globalData.userInfo)
  },
  lost(e) {
    this.setData({
      amount: e.detail.value
    })
  }
})